(function(){
	angular.module("personalCtrlmodule",[])
		.controller("personalController",["$scope",
			"$ionicModal","modalDataService","USERDATA",
			function($scope,$ionicModal,
                modalDataService,USERDATA){
				$scope.loginPageShow = function(){
                    $ionicModal.fromTemplateUrl('tpl/login.html', {
                        animation: 'slide-in-up'
                    }).then(function(modal) {
                        $scope.modal = modal;
                        modalDataService.myModal = modal;
                        $scope.modal.show();
                    });
                };
                 $scope.loginOut = function(){
                    USERDATA.isLogin = false;
                    $scope.isLogin = false;
                    USERDATA.user = null;
                    $scope.username = null;
                   	$scope.$broadcast("isLogin");
                    // $scope.$emit("isLogin");
                    // $scope.$emit("loginSuccess");
                    // $scope.$broadcast("loginSuccess");
                    // $scope.$broadcast("isLogin");
                    // $scope.$emit("isLogin");
                };
                $scope.$on("isLogin",function(){
                	console.log("hehe");
                        USERDATA.isLogin = false;
                    	$scope.isLogin = false;
	                    USERDATA.user = null;
	                    // $scope.username = null;
                    })
				$scope.$on("loginSuccess",function(){
                    console.log("loginSuccess");
                    USERDATA.isLogin = true;
                    $scope.isLogin = true;
                    // $scope.isLogin = !$scope.isLogin;
                    // $scope.$broadcast("isLogin");
                    $scope.username = USERDATA.user.user_name;
                    console.log(USERDATA.user);
                    $scope.userid = USERDATA.user.user_id;
                });
			}])
})();